using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FastPoster.DataProviders.DAO
{
	#region using
	using System.Data;
	using FastPoster.DataProviders.DTO;
    using System.Data.OleDb;
	#endregion
	public class BoxDAO : AbstractDAO
	{
		public BoxDAO(String strPath): base(strPath)
		{
		}

        public DataSet RetrieveMaxID()
        {
            DataSet ds;
            try
            {
                ds = new DataSet();
                base.sql = "usp_Box_RetrieveMaxID";
                base.FillDataSet(ref ds, "Box");
                return ds;
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            finally
            {
                base.CleanUpObject();
            }
        }

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_Box_SelectAll";
				base.FillDataSet(ref ds, "Box");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByID(int id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_Box_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				base.FillDataSet(ref ds, "Box");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

        public DataSet SelectByDienDanAnhDanhMuc(int iddiendan, int iddanhmuc)
        {
            DataSet ds;
            try
            {
                ds = new DataSet();
                base.sql = "usp_Box_SelectByDienDanAnhDanhMuc";
                base.InitializeCommand();
                base.AddParameter("@IDDienDan", OleDbType.Integer, 1000, iddiendan);
                base.AddParameter("@IDDanhMuc", OleDbType.Integer, 1000, iddanhmuc);
                base.FillDataSet(ref ds, "Box");
                return ds;
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            finally
            {
                base.CleanUpObject();
            }
        }

		public bool Insert(BoxDTO obj)
		{
			try
			{
				base.sql = "usp_Box_Insert";
				base.InitializeCommand();
				base.AddParameter("@IDDienDan", OleDbType.Integer, 1000, obj.IDDienDan);
				base.AddParameter("@IDDanhMuc", OleDbType.Integer, 1000, obj.IDDanhMuc);
				base.AddParameter("@URL", OleDbType.VarChar, 1000, obj.URL);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                throw new Exception(ex.Message, ex.InnerException);
			}
		}

		public bool Update(BoxDTO obj)
		{
			try
			{
				base.sql = "usp_Box_Update";
				base.InitializeCommand();
				base.AddParameter("@URL", OleDbType.VarChar, 1000, obj.URL);
                base.AddParameter("@ID", OleDbType.Integer, 1000, obj.ID);
				return ExecuteStoredProcedure();
			}
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
		}

		public bool Delete(int id)
		{
			try
			{
				base.sql = "usp_Box_Delete";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.Integer, 1000, id);
				return ExecuteStoredProcedure();
			}
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
		}

        public bool DeleteByIDDienDan(int iddiendan)
        {
            try
            {
                base.sql = "usp_Box_DeleteByIDDienDan";
                base.InitializeCommand();
                base.AddParameter("@IDDienDan", OleDbType.Integer, 1000, iddiendan);
                return ExecuteStoredProcedure();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
        }

		public DataSet SelectByIDDienDan(int iddiendan)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_Box_SelectByIDDienDan";
				base.InitializeCommand();
				base.AddParameter("@IDDienDan", OleDbType.Integer, 1000, iddiendan);
				base.FillDataSet(ref ds, "Box");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

		public DataSet SelectByIDDanhMuc(int iddanhmuc)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_Box_SelectByIDDanhMuc";
				base.InitializeCommand();
				base.AddParameter("@IDDanhMuc", OleDbType.Integer, 1000, iddanhmuc);
				base.FillDataSet(ref ds, "Box");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

	}
}